package com.karson.admin.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.karson.admin.service.LoginService;
import com.karson.common.model.SystemAdmin;
import com.karson.common.request.LoginAdminRequest;
import com.karson.common.request.LoginMobileRequest;
import com.karson.common.request.LoginRequest;
import com.karson.common.response.CommonResult;
import com.karson.common.response.LoginAdminResponse;
import com.karson.common.response.LoginResponse;

import com.karson.common.response.SystemAdminResponse;
import com.karson.service.service.SystemRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 登录测试
 * @author ZKS
 */
@RestController
@RequestMapping("/api/admin")
@Tag(name = "登录控制器接口")
public class LoginController {

    @Autowired
    private LoginService loginService;
    @Autowired
    private SystemRoleService systemRoleService;

    @Operation(summary = "登录接口")
    @PostMapping("/login")
    public CommonResult<LoginAdminResponse> login(@RequestBody LoginAdminRequest loginAdminRequest, HttpServletRequest request) {
        return CommonResult.success(loginService.login(loginAdminRequest,request));
    }
    @Operation(summary = "登录接口")
    @PostMapping("/register")
    public CommonResult<Void> register(@RequestBody @Validated LoginAdminRequest loginAdminRequest){
        loginService.register(loginAdminRequest);
        return CommonResult.success(null);
    }
    @Operation(summary = "退出接口")
    @GetMapping("/logout")
    public CommonResult<String> logout(){
        StpUtil.logout();
        return CommonResult.success("成功退出");
    }


    @Operation(summary = "获取用户信息")
    @GetMapping("/info")
    public CommonResult<SystemAdminResponse> getAdminInfo(){
        SystemAdminResponse systemAdminResponse = loginService.getAdminInfo();
        return CommonResult.success(systemAdminResponse);
    }


}
